using UnityEngine;
using QFramework;
using UnityEditor.Search;

namespace Projectsurviva
{
	public partial class SimpleAex : ViewController
	{
		void Start()
		{
			// Code Here
		}
		float mcurrentSeconds = 0;
        private void Update()
        {
            mcurrentSeconds += Time.deltaTime;
			if(mcurrentSeconds>1.0f)
			{
				Axe.Instantiate().Show()
					.Position(this.Position())
					.Self(self => 
				{
				 var rigidbody2d=self.GetComponent<Rigidbody2D>();
		         var randomx=RandomUtility.Choose(-8, -5,-3, 3,5, 8);
					var randdomY = RandomUtility.Choose(3,5,8);
					rigidbody2d.velocity = new Vector2(randomx, randdomY);
					self.OnTriggerEnter2DEvent(collieder => 
					{
                        var hurtbox = collieder.GetComponent<HurtBoxenemy>();
                        if (hurtbox != null)
                        {
							if(Play.Default)
							{

                            if (hurtbox.Owener.CompareTag("Enemy"))
                            {
                                hurtbox.Owener.GetComponent<Enemy>()?.Hurt(2);
                            }
							}
                        }
                    }).UnRegisterWhenGameObjectDestroyed(gameObject);

					ActionKit.OnUpdate.Register(() =>
					{
						if(Play.Default.Position().y-self.Position().y>15)
						{
							self.DestroyGameObjGracefully();
						}
					}).UnRegisterWhenGameObjectDestroyed(self);
				});
				mcurrentSeconds = 0;
			}
        }
    }
}
